package 曾世昌12_19.demo7;

import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DateConverter;

import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.HashMap;

public class Demo {

    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException {
        demo01();
    }

    public static void demo01() throws InvocationTargetException, IllegalAccessException {
        HashMap<String, Object[]> map = new HashMap<>();
        map.put( "bookname", new Object[]{"钢铁是怎样炼成的"} );
        map.put( "author", new Object[]{"奥斯特洛夫斯"} );
        map.put( "price", new Object[]{50.6} );
        map.put( "publishDate", new Object[]{"2001-01-02"} );
        DateConverter dateConverter = new DateConverter();
        dateConverter.setPatterns( new String[]{"yyyy-MM-dd"} );
        ConvertUtils.register( dateConverter, Date.class );
        Book book = new Book();
        MyBeanUtils.populate(book, map );
    }
}
